<!doctype html>
<html>
<head>
	<meta charset="utf-8" />
	<title>Validation</title>
	<link rel="stylesheet" type="text/css"  href="../../../../kissy-dpl/base/build/css/dpl-pkg.css" />
	<script src="../../../build/kissy.js" charset="utf-8"></script>
	
	<link rel="stylesheet" type="text/css"  href="doc.css" /> <script src="doc.js" charset="utf-8"></script>
	<script type="text/javascript" src="../../../tools/utils/syntaxhighlighter_3.0.83/scripts/shCore.js"></script>
<script type="text/javascript" src="../../../tools/utils/syntaxhighlighter_3.0.83/scripts/shBrushJScript.js"></script>
<link type="text/css" rel="stylesheet" href="../../../tools/utils/syntaxhighlighter_3.0.83/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.all();</script>

	

	
</head>
<body>
 

<div class="note">
<pre class="brush: js;">

	/** 在KISSY.Validation中，每一个字段其实都是以KISSY.Validation.Field的实例形式存在的。 **/

	var check = new Validation(form,{
		style: "under"
	});
				
	// 方法一： 增加Auth.Field实例
	f1 = new Validation.Field("#password",{
		style: "under",
		length:[6,30,true]
	});
	
	check.add(f1);
	
				
	//方法二： 通过配置增加
	check.add("#username", {
		email:true
	});
			
			
</pre>
</div>
 
 
<div id="viewdemo" class="doc">

	


	<form method="post">
	<ul class="form">

		<li>
			<label class="hd">用户名：</label>
			<input class="text" type="text" name="username" id="username"/>
		</li>
		
		<li>
			<label class="hd">密码：</label>
			<input class="text" type="text" name="password" id="password"/>
		</li>

		<li>
			<label class="hd"></label>
			<p><a href="" id="add">+ 增加一个字段</a> 通过编程的方式动态添加校验字段</p>
		</li>

		<li>
			<button type="submit">提交</button>
		</li>

	</ul>
	</form>

	<script>
	
		KISSY.use("validation",function(S,Validation){
            var $=S.all;

			var form = S.query("form")[0],
			
				check = new Validation(form,{
					style: "under"
				}),
				
				// 方法一： 增加Auth.Field实例
				f1 = new Validation.Field("#password",{
					style: "under",
					length:[6,30,true]
				});
				
			//方法二： 通过配置增加
			check.add("#username", {
				email:true
			});
			
			check.add(f1);
			
			
			KISSY.Event.on(form,"submit",function(){
				check.isValid();
				return false;
			});




            $("#add").on("click",function(ev){
                ev.halt();
                var a = S.DOM.create('<input class="text" type="text" name="test" id="test"/>');
                $(this).parent().parent().append (a);
                $(this).parent().remove();
				f1 = new Validation.Field(a,{
					style: "under",
					length:[6,30,true]
				});
            });


			
		});

	</script>


</div>





</body>
</html>
